﻿#pragma once
#include "GameCore.h"
#include "AngelScriptBinder.h"

_NAMESPACE_BEGIN

/// 游戏内核模块的脚本绑定类
class Core_ScriptBinder
{
public:
	
	/// 单体类声明
	SINGLETON_HELPER(Core_ScriptBinder);

	/// 构造函数
	Core_ScriptBinder();		

protected:
	//int Bind_int3( asIScriptEngine* engine );
private:
};

REGISTER_TYPEMETHODS(ASEvent)
{
	r=engine->RegisterObjectMethod(type,"void SetHandler(EventHandler@,const string& in)",asMETHOD(T,SetHandler), asCALL_THISCALL);	 assert( r >= 0 );
	r=engine->RegisterObjectMethod(type,"void call()",asMETHODPR(T,call,(),void), asCALL_THISCALL);	 assert( r >= 0 );
	//r=engine->RegisterObjectMethod(type,"void call(const any& in)",asMETHODPR(T,call,(CONST_REF(boost::any)),void), asCALL_THISCALL);	 assert( r >= 0 );
	//r=engine->RegisterObjectMethod(type,"void call(const any& in,const any& in)",asMETHODPR(T,call,(CONST_REF(boost::any),CONST_REF(boost::any)),void), asCALL_THISCALL);	 assert( r >= 0 );
}

REGISTER_TYPEMETHODS(Panel)
{
	r=engine->RegisterObjectMethod(type,"void Initial()", asMETHOD(T,Initial), asCALL_THISCALL);	 assert( r >= 0 );
	r=engine->RegisterObjectMethod(type,"void PlugTo(Panel@)",asMETHOD(T,PlugTo), asCALL_THISCALL);	 assert( r >= 0 );
	r=engine->RegisterObjectMethod(type,"Panel@ FindPlugin(const string& in)",asMETHOD(T,FindPlugin), asCALL_THISCALL);	 assert( r >= 0 );

}

REGISTER_TYPEMETHODS(ParentPanel)
{
	BASEMETHODS(type,T,Panel)
		r=engine->RegisterObjectMethod(type,"void AddSon(Panel@)", asMETHOD(T,AddSon), asCALL_THISCALL);	 assert( r >= 0 );
	r=engine->RegisterObjectMethod(type,"void RemoveSon(Panel@)", asMETHOD(T,RemoveSon), asCALL_THISCALL);	 assert( r >= 0 );
}

REGISTER_TYPEMETHODS(GameCore)
{
	BASEMETHODS(type,T,Panel)
	r = engine->RegisterObjectMethod
		(type, "void RegistScriptObj(const string&in,EventHandler@)", 
		asMETHOD(T,RegistScriptObj),asCALL_THISCALL); assert( r >= 0 );				
}

using boost::any;
template<typename T>
void cast_pod2any(T value,any* self)
{
	new(self) any();
	*self=value;	
}
template<typename T>
void cast_value2any(CONST_REF(T) value,any* self)
{
	new(self) any();
	*self=value;	
}
template<typename T>
T cast_any2value(any* self)
{
	return boost::any_cast<T>(*self);
}


_NAMESPACE_END